package com.sangmo.fts.teacher.service;

import com.sangmo.boot.framework.plugin.dataview.crud.service.BaseViewService;
import com.sangmo.boot.framework.plugin.dataview.data.IDataViewRepo;
import com.sangmo.fts.teacher.interfaces.DurationRatioSettingCreation;
import com.sangmo.fts.teacher.interfaces.GrowthRatioSettingCreation;
import com.sangmo.fts.teacher.model.DurationRatioSetting;
import com.sangmo.fts.teacher.repo.DurationRatioSettingRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class DurationRatioSettingEntityService extends BaseViewService<DurationRatioSetting> {

    @Autowired
    private DurationRatioSettingRepo durationRatioSettingRepo;

    @Override
    protected IDataViewRepo<DurationRatioSetting> getRepo() {
        return durationRatioSettingRepo;
    }

    public void create(Long scoreSettingId, List<DurationRatioSettingCreation> list) {
        for (DurationRatioSettingCreation bo : list) {
            bo.setScoreSettingId(scoreSettingId);
            this.create(bo);
        }
    }

    public void deleteByScoreSettingId(Long scoreSettingId) {
        durationRatioSettingRepo.deleteByScoreSettingId(scoreSettingId);
    }

    public List<DurationRatioSetting> findByScoreSettingId(Long scoreSettingId) {
        return durationRatioSettingRepo.findByScoreSettingIdOrderByMaxValueDesc(scoreSettingId);
    }
}
